import table from '@/components/dt/table/render.js'
import nameOpt from '@/biz/option/name.js'
import dateOpt from '@/biz/option/date.js'
import Opt from '@/components/dt/info/Opt.js'
import dt from '@dt/dt'
import moment from 'moment'

let _this = null

class ColumnAllot extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    let p0 = [{
      type: 'checkbox',
      width: 40,
      align: 'center',
    },
    {
      field: 'customerPhone',
      minWidth: 200,
      title: '线索手机号',
      header: {
        filter: {
          title: '线索手机号',
          key: 'customerPhone',
          placeholder: '请输入线索手机号',
          input: {},
        },
      }
    }]
    let p1 = [{
      field: 'isPrivacy',
      minWidth: 200,
      title: '隐私号回拨',
      header: {
        filter: {
          title: '隐私号回拨',
          key: 'isPrivacy',
          placeholder: '请选择',
          select: {
            options: [{ key: '1', value: '是' }, { key: '0', value: '否' }],
          }
        }
      },
      cell: {
        value: item => item.isPrivacy == 1 ? '是' : '否',
        text: {}
      }
    }]
    let p2 = [{
      field: 'customerName',
      minWidth: 200,
      title: '客户姓名',
      header: {
        filter: {
          title: '客户姓名',
          key: 'customerName',
          placeholder: '请输入客户姓名',
          input: {},
        },
      }
    }]
    let p3 = [
    {
      title: '线索生成时间',
      field: 'updateTime',
      minWidth: 180,
      header: {
        filter: dateOpt.range({
          title: '线索生成时间',
          startKey: 'startTime',
          endKey: 'endTime',
          disabled: (date) => {
            return date.valueOf() > new Date().getTime()
          },
          check: (val) => {
            if (_this.$tool.dateDiff(val.startTime, val
                .endTime).Y >= 2) {
              // 日期最大跨度两年
              _this.$Message.warning('日期跨度至多两年。')
            }
            return !(_this.$tool.dateDiff(val.startTime, val
              .endTime).Y >= 2)
          }
        }),
      },
      cell: {
        value: (item) => moment(item.updateTime).format('YYYY-MM-DD HH:mm'),
        text: {}
      }
    },
    {
      field: 'allocatedStatus',
      minWidth: 160,
      header: {
        filter: {
          title: '线索推送结果',
          key: 'allocatedStatus',
          placeholder: '请选择线索推送结果',
          select: {
            options: [
              { key: 1, value: '成功' },
              { key: 2, value: '失败' },
            ],
            multiple: false,
            filterable: false,
          }
        }
      },
      cell: {
        value: item => item.allocatedStatus == 1 ? '成功' : '失败',
        text: {}
      }
    },
    {
      field: 'allocatedMessage',
      minWidth: 200,
      title: '推送结果说明',
      header: {
        filter: {
          title: '推送结果说明',
          key: 'allocatedMessage',
          placeholder: '请输入推送结果说明',
          input: {},
        },
      }
    }]
    let p4 = [
    {
      field: 'customerSource',
      minWidth: 200,
      title: '客户来源',
      header: {
        filter: {
          title: '客户来源',
          key: 'customerSource',
          placeholder: '请输入客户来源',
          input: {},
        },
      }
    },
    {
      field: 'buildingIntention',
      minWidth: 200,
      title: '初始意向楼盘',
      header: {
        filter: {
          title: '初始意向楼盘',
          key: 'buildingIntention',
          placeholder: '请输入初始意向楼盘',
          input: {},
        },
      }
    },
    {
      field: 'channelSource',
      minWidth: 160,
      header: {
        filter: {
          title: '渠道',
          key: 'channelSource',
          placeholder: '请选择渠道',
          select: {
            options: [{ key: '同策好房', value: '同策好房' }, { key: '客户复用', value: '客户复用' }],
          }
        }
      }
    },
    {
      field: 'batchName',
      minWidth: 200,
      title: '所属批次'
    },
    {
      title: '导入日期',
      field: 'createTime',
      minWidth: 180
    },
    {
      field: 'remarks',
      minWidth: 200,
      title: '客户情况说明',
      header: {
        filter: {
          title: '客户情况说明',
          key: 'remarks',
          placeholder: '请输入客户情况说明',
          input: {},
        },
      },
      slots: {
        default: (params, h) => {
          return table.cell.text(h, {
            value: params.row.remarks,
            lineClamp: 2,
            webkitBoxOrient: 'vertical',
            display: '-webkit-box',
            whiteSpace: 'initial',
            lineHeight: 1
          })
        }
      }
    }]
    let p5 = [{
      field: 'userName',
      minWidth: 200,
      title: '推送人员',
      header: {
        filter: nameOpt.create({
          key: 'userName',
          title: '推送人员',
          to: (info) => {
            return {
              userName: info.name
            }
          }
        })
        // filter: {
        //   title: '推送人员',
        //   key: 'userName',
        //   placeholder: '请输入推送人员',
        //   input: {},
        // },
      }
    }]
    let p6 = [{
      field: 'caseLocation',
      minWidth: 150,
      title: '所属事业部'
    }, {
      field: 'caseLocationTwo',
      minWidth: 150,
      title: '所属子公司'
    }, {
      field: 'department',
      minWidth: 150,
      title: '所属事业处'
    }, {
      field: 'buildingName',
      minWidth: 150,
      title: '所属案场'
    }, {
      field: 'updaterName',
      minWidth: 150,
      title: '操作人',
      header: {
        filter: nameOpt.create({
          key: 'userName',
          title: '操作人',
          to: (info) => {
            return {
              updaterName: info.name
            }
          }
        })
        // filter: {
        //   title: '操作人',
        //   key: 'updaterName',
        //   placeholder: '请输入操作人工号',
        //   input: {}
        // }
      },
    }, {
      field: 'allocatedTime',
      minWidth: 150,
      title: '操作时间',
      cell: {
        value: (item) => moment(item.allocatedTime).format('YYYY-MM-DD HH:mm'),
        text: {}
      }
    }]
    this.all = []
    if (_this.name == 'no_Allot') {
      this.all = [...p0, ...p2, ...p4]
    } else if (_this.name == 'wait_Allot') {
      this.all = [...p0, ...p1, ...p2, ...p5, ...p4, ...p6]
    } else if (_this.name == 'rejected_Allot') {
      this.all = [...p0, ...p1, ...p2, ...p5, ...p3, ...p4, ...p6]
    }
  }

}

class ColumnSelectUser extends Opt {
  constructor(vm) {
    super()
    _this = vm
    this.build()
  }

  build() {
    this.createAll()
    this.opts.push(...this.all)
  }

  createAll() {
    this.all = [
    {
      type: 'checkbox',
      width: 40,
      align: 'center',
    },
    {
      field: 'userName',
      minWidth: 120,
      title: '姓名',
      cell: {
        value: (item) => `${item.userName} (${item.workNo})`,
        text: {}
      }
    },
    {
      field: 'isReceiver',
      minWidth: 120,
      title: '是否为承接人',
      cell: {
        value: (item) => item.isReceiver == 1 ? '是' : '否',
        text: {}
      }
    },
    {
      field: 'phone',
      minWidth: 200,
      title: '手机号',
    }]
  }

}
export default { ColumnAllot, ColumnSelectUser }